//
//  GuidePageViewController.swift
//  FoodPin
//
//  Created by 王巍 on 16/5/10.
//  Copyright © 2016年 ww. All rights reserved.
//

import UIKit

class GuidePageViewController: UIPageViewController, UIPageViewControllerDataSource {

    // 数据源
    var headings = ["私人定制", "餐馆定位", "美食发现"]
    var images = ["foodpin-intro-1", "foodpin-intro-2", "foodpin-intro-3"]
    var footers = ["好店随时加，打造自己的美食向导", "马上找到饕鬄大餐之馆的位置", "发现其他吃货的珍藏"]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        dataSource = self
        
        if let startVC = viewControllerAtIndex(0){
            setViewControllers([startVC], direction: .Forward, animated: true, completion: nil)
        }
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
        
        var index = (viewController as! GuideContentViewController).index
        
        index += 1
        
        return viewControllerAtIndex(index)
        
    }
    
    func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
        
        var index = (viewController as! GuideContentViewController).index
        
        index -= 1
        
        return viewControllerAtIndex(index)
    }
    
    /*
    // 系统默认页码
    func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
        
        return headings.count
    }
    
    
    func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
        
        return 0
    }
     */
    
    func viewControllerAtIndex(index:Int) -> GuideContentViewController? {
        
        if case 0 ..< headings.count = index{
            if let contentVC = storyboard?.instantiateViewControllerWithIdentifier("guideContentController") as? GuideContentViewController{
                
                contentVC.heading = headings[index]
                contentVC.footer = footers[index]
                contentVC.imageName = images[index]
                contentVC.index = index
                
                return contentVC
            }
        }
        
        return nil
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
